<html>
<head>
    <meta charset="utf-8">
    <script src="./js/setupin.js"></script>
    <script src="./js/axios.js"></script>
</head>

<script setup>
    import {ref} from 'vue'

    const qrcode = ref('')
    let count = 0

    const login = async () => {
        const res = await axios.get('http://localhost:8080/wxLogin', {
            params: null,
            responseType: 'blob'
        })
        qrcode.value = URL.createObjectURL(res.data)
    }

    setInterval(() => {
        count++
        if (count % 5 == 0) {
            axios.get('http://localhost:8080/getUser').then(res => {
                if (res.data !== null && res.data !== '') {
                    if (res.data.openid !== '') {
                        window.location.href = 'http://localhost:8080/user.html'
                    }
                }
            })
        }
    },1000)


    /*setInterval(async () => {
        count++
        if (count % 5 == 0) {
            const data = await axios.get('http://localhost:8080/getUser')
            console.log(data.data)

            if (data.data !== null){
                console.log(data.data)
                console.log(123)
            }
            /!*if (data != null) {
                if (data.openid != '') {
                    window.location.href = 'http://localhost:8080/user.html'
                }
            }*!/
        }
    }, 1000)*/
</script>

<template>
    <h1>微信扫码登录</h1>
    <div>
        <button @click="login">扫码登录</button>
        <img :src="qrcode" alt="">
    </div>
    </div>

</template>
</html>